/*
 * @lc app=leetcode.cn id=11 lang=javascript
 *
 * [11] 盛最多水的容器
 */

// @lc code=start
/**
 * @param {number[]} height
 * @return {number}
 */
var maxArea = function(height) {
  let l = 0;
  let r = height.length - 1;
  let result = 0;
  while(l < r){
    let s = (r - l) * Math.min(height[l], height[r]);
    result = Math.max(result, s);
    if(height[l]< height[r]){
      l++;
    } else {
      r--;
    }
  }
  return result;
};


/**
 * 复习 2021-08-04
 */
// 超时
// var maxArea = function(height) {
//   let pre = 0, tail = 0;
//   let max = 0;
//   while(pre < height.length){
//     tail = pre + 1;
//     while(tail < height.length){
//       let min = Math.min(height[pre], height[tail]);
//       max = Math.max(max, (tail - pre) * min)
//       tail++;
//     }
//     pre++;
//   }
//   return max;
// }

// 从两边完中间靠拢，扔掉矮的木板
var maxArea = function(height) {
  let l = 0;
  let r = height.length - 1;
  let result = 0;
  while(l < r){
    let s = (r - l) * Math.min(height[l], height[r]);
    result = Math.max(result, s);
    if(height[l]< height[r]){
      l++;
    } else {
      r--;
    }
  }
  return result;
};
// @lc code=end

